import pymongo

client = pymongo.MongoClient('localhost', 27017)
db = client.mydb

# 添加数据
def add(article):
	message = db.message
	# 查询数据
	query = {
		'id' : article['id']
	}
	rs = message.find_one(query)
	# 没有重复，进行添加
	if not rs:
		article['page_view'] = 0
		message.insert(article)
		# return 1
	else:
		exit()

# 更新分类
def updateClassify(column):
	classify = db.classify
	# 查询数据
	query = {
		'column_id' : column['column_id']
	}
	rs = classify.find_one(query)
	# 更新
	if rs:
		query = {
			'column_id' : column['column_id']
		}
		new = {
			'$set' : {
				'column_name' : column['column_name']
			}
		}
		classify.update_one(query,new)
	# 添加
	else:
		classify.insert(column)